package com.sdry.utils;


import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;

/**
 * @ClassName: DownloadUtil
 * @Description: 文件上传功能
 * @Author cb
 * @Date 2018/4/25 10:00
 * @version 1.0
 */
public class DownloadUtil {

    public static String upload(HttpServletRequest request , MultipartFile file) throws IOException {

        String path = request.getSession().getServletContext().getRealPath("/upload");
        String fileName = file.getOriginalFilename();
        File dir = new File(path, fileName);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        //MultipartFile自带的解析方法
        file.transferTo(dir);

        return path;
    }
}
